/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package   com.edi.proxy.component
{
	import com.edi.runtime.component.EDIApplication;
	
	public class ServerProxy
	{
	
		public static function getWebInfo(dsName:String,serviceName:String,methods:String,param:Array,result:Function,fault:Function=null):void
		{
			var appName:String=EDIApplication.appName;
			appName=appName.indexOf(".app")==-1?appName+".app":appName;
			var	diskHP:HttpProxy=new HttpProxy(EDIApplication.appName,false,null);
			diskHP.url=EDIApplication.path+appName; 
			var webDisk:SPOParam=new SPOParam();
			webDisk.dsName=dsName;
			webDisk.serviceName=serviceName;
			webDisk.methods=methods;
			if(param!=null)
			{
				for(var i:int=0;i<param.length;i++)
				{
					webDisk.addParameters(param[i]["name"],param[i]["value"]);
				}
			}
			diskHP.addPoParam(webDisk);
			diskHP.resultCallback=result;
			diskHP.faultCallBack=fault;
			diskHP.send();	
		}
		
		public static function getPOList(dsName:String,POList:Array,result:Function,fault:Function=null):void
		{
			var	diskHP:HttpProxy=new HttpProxy(dsName,false,null);
			var appName:String=EDIApplication.appName;
			appName=appName.indexOf(".app")==-1?appName+".app":appName;
			diskHP.url=EDIApplication.path+appName; 
			
			for(var i:int=0;i<POList.length;i++)
			{
				diskHP.addPoParam(POList[i]);
			}
			diskHP.resultCallback=result;
			diskHP.faultCallBack=fault;
			diskHP.send();	
		}
		
		public static function newPOParam(dsName:String,serviceName:String,methods:String,param:Array):SPOParam
		{
			var webDisk:SPOParam=new SPOParam();
			webDisk.dsName=dsName;
			webDisk.serviceName=serviceName;
			webDisk.methods=methods;
			if(param!=null)
			{
				for(var i:int=0;i<param.length;i++)
				{
					webDisk.addParameters(param[i]["name"],param[i]["value"]);
				}
			}
			return webDisk;
		}
	}
}